package com.yxy.controller;

import com.yxy.base.BusinessException;
import com.yxy.base.RestResponse;
import com.yxy.feign.AuthService;
import com.yxy.feign.DTO.AppUserCreateDto2;
import com.yxy.utils.SystemSettingHelper;
import com.yxy.utils.TokenCheckUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yuxiaoyang
 * app登录用户相关接口
 */
@RestController
@Slf4j
@RequestMapping("/app-user")
public class AppUserController {

  @Autowired
  private TokenCheckUtil tokenCheckUtil;

  @Autowired
  private AuthService authService;

  // 根据主键id获取某个字典项的详情
  @PostMapping("/createOrUpdate2")
  public RestResponse createOrUpdate2(@RequestBody AppUserCreateDto2 inputDto) throws BusinessException {
    String invokeUnionAuthToken = tokenCheckUtil.getInvokeUnionAuthToken();
    return authService.createOrUpdateAppUser(inputDto, invokeUnionAuthToken);
  }

  //app user登录后删除其他app user
  @DeleteMapping("/{id}")
  public RestResponse delete(@PathVariable("id") long id) throws BusinessException {
    String invokeUnionAuthToken = tokenCheckUtil.getInvokeUnionAuthToken();
    return authService.deleteAppUser(id, invokeUnionAuthToken);
  }
}
